﻿////////////////////////////////////////////////////////////////////////////////////////////////////////////
/* 
#选项卡 
*/
var tab = {
	//text
	item: function(id,tag,type,speed,Time){
		var obj = this;
		obj.id = $(id);
		obj.index = 0;
		obj.type = type || ''; //事件
		obj.speed = speed || 2000;
		obj.Time = Time || "slow";
		obj.em = obj.id.children('dt').children('em');
		if(obj.type.length){
			obj.em.bind(type,function(){
				return Marquee(this);
			});
		}else{
			obj.id.hover(
				function(){ 
					clearInterval(obj.MyMar);
				},
				function(){ 
					obj.MyMar = setInterval(Marquee,obj.speed);
				}
			);
			obj.em.mouseover(function(){
				return Marquee(this)
			});
			obj.MyMar = setInterval(Marquee,obj.speed);
		}
		function Marquee(e){
			obj.tag = obj.id.children('dd').children(tag);
			obj.index = e?obj.em.index(e):obj.index<obj.em.length-1?obj.index+1:0;
			obj.em.eq(obj.index).addClass('off').siblings().removeClass('off');
			obj.tag.stop().hide().css({"opacity": 1}).eq(obj.index).fadeIn(obj.Time);
		}
	},
	// Img
	Image: function(id,tag,type,speed,Time){
		var obj = this;
		obj.id = $(id);
		obj.index = 0;
		obj.type = type || ''; //事件
		obj.speed = speed || 2000;
		obj.Time = Time || 400;
		obj.em = obj.id.children('dd').children('span');
		if(obj.type.length){
			obj.em.bind(type,function(){
				return Marquee(this);
			});
		}else{
			obj.id.hover(
				function(){ 
					clearInterval(obj.MyMar);
				},
				function(){ 
					obj.MyMar = setInterval(Marquee,obj.speed);
				}
			);
			obj.em.mouseover(function(){
				return Marquee(this)
			});
			obj.MyMar = setInterval(Marquee,obj.speed);
		}
		function Marquee(e){
			obj.tag = obj.id.children('dt').children(tag);
			obj.index = e?obj.em.index(e):obj.index<obj.em.length-1?obj.index+1:0;
			obj.em.eq(obj.index).addClass('off').siblings().removeClass('off');
			obj.tag.hide().attr("src",obj.em.eq(obj.index).children().attr("src")).fadeIn(obj.Time);
		}
	},
	// Pic
	Pic: function(id,tag,type,speed,Time){
		var obj = this;
		obj.id = $(id);
		obj.index = 0;
		obj.type = type || ''; //事件
		obj.speed = speed || 2000;
		obj.Time = Time || 400;
		obj.ul = obj.id.find('ul');
		obj.em = obj.ul.children('li');
		
		if(obj.type.length){
			obj.em.bind(type,function(){
				return Marquee(this);
			});
		}else{
			obj.ul.hover(
				function(){ 
					clearInterval(obj.MyMar);
				},
				function(){ 
					obj.MyMar = setInterval(Marquee,obj.speed);
				}
			);
			obj.em.mouseover(function(){
				return Marquee(this)
			});
			obj.MyMar = setInterval(Marquee,obj.speed);
		}
		var h = 0;
		var can = false;
		obj.id.find("h3").click(function(){
			if(can){ return false; }
			can = true;
			var _this = this;
			h = (obj.ul.scrollTop()-obj.ul.height());
			if((h - obj.id.height()) > 0){obj.id.find("h4").find("span").removeClass("off"); }
			obj.ul.animate({ scrollTop : h +"px"},"slow",function(){
				if((obj.ul.scrollTop() - obj.ul.height()) <= 0){
					$(_this).find("span").addClass("off");
				}
				can = false;
			});
		});
		obj.id.find("h4").click(function(){
			if(can){ return false; }
			can = true;
			var _this = this;
			h = (obj.ul.scrollTop() + obj.ul.height());
			if((h + obj.id.height()) <= obj.ul[0].scrollHeight){ obj.id.find("h3").find("span").removeClass("off"); }
			obj.ul.animate({ scrollTop : h +"px" },"slow",function(){
				if((obj.ul.height() + obj.ul.scrollTop()) >= obj.ul[0].scrollHeight){
					$(_this).find("span").addClass("off");
				}
				can = false;
			});
		});
		
		function Marquee(e){
			obj.tag = obj.ul.children('li');
			obj.index = e?obj.em.index(e):obj.index<obj.em.length-1?obj.index+1:0;
			obj.em.eq(obj.index).addClass('off').siblings().removeClass('off');
			$("#showpic img").hide().attr("src",obj.em.eq(obj.index).children().attr("src")).fadeIn(obj.Time);
			$("#showTopic").html(obj.em.eq(obj.index).attr("title"));
		}
	}
}
/* 
#选项卡 End
*/
////////////////////////////////////////////////////////////////////////////////////////////////////////////
/* 
#上下滚动
*/
function $Id(id){ return document.getElementById(id); }
var demo = {
	item: function(e){
		var box = $Id(e.id)
		var s = e.s || 1500; //停顿事件
		var px = e.px || -1 ;//滚动像素
		var can = true;
		box.innerHTML += box.innerHTML;
		box.onmouseover= function(){can = false};
		box.onmouseout = function(){can = true};
		var max = parseInt(box.scrollHeight/2);
		var h = e.h || max;	//停顿滚动高度
		new function (){
			if(can){ 
				var set = px<1?[0,max]:[max,0];
				box.scrollTop == set[0]?box.scrollTop = set[1]:box.scrollTop+=px;
			};
			setTimeout(arguments.callee,box.scrollTop%h?10:s);
		};
	}
}
/* 
#上下滚动 End
*/
////////////////////////////////////////////////////////////////////////////////////////////////////////////
/* 
#内容折叠
*/
function ShowAllContent(obj){
	if(!obj.rel){ obj.rel = 60; }
	var partag = $(obj).parent();
	var span = partag.children("span");
	if(obj.title == "全部"){
		obj.title = "精简";
		span[0].style.display = "none";
		span[1].style.display = "";
		obj.innerHTML = obj.innerHTML.replace("全部","精简");
		obj.parentNode.style.height = "auto";
		this.hei = partag.height();
		partag.height(obj.rel).animate({"height": this.hei +"px"},"slow");
	}else{
		obj.title = "全部";
		obj.innerHTML = obj.innerHTML.replace("精简","全部");
		partag.animate({"height": obj.rel +"px"},"slow",function(){
			span[0].style.display = "";
			span[1].style.display = "none";
		});
	}
}
/* 
#内容折叠 End
*/


/* 
#图层相册
*/

var drag = {
	item: function(){	
		var obj = this;
		obj.dragLayer = this.dragLayer;
		obj.dragTag = this.dragTag || this.dragLayer;
		obj.range = this.range || false;
		//obj.bodyT = this.bodyT || false;
		obj.dragArea = htm.Top();
		var x=0,y=0,l=0,t=0,d = {};
		obj.isdrag = false;
		obj.dragTag.mousedown(function(e){
			obj.isdrag = true;
			
			t = parseInt(obj.dragLayer.position().top+0);
			l = parseInt(obj.dragLayer.position().left+0);
			e = e || event;
			x = e.pageX;
			y = e.pageY;
			if(this.setCapture){ this.setCapture();}
			$(document).mousemove(function(c){
				c = c || event;
				if(obj.isdrag){
					d.t = (t + c.pageY - y);
					d.l = (l + c.pageX - x);
					if(obj.range){
						d.h = htm.Height()+obj.dragArea-obj.dragLayer.outerHeight();
						d.w = htm.Width()-obj.dragLayer.outerWidth();
						d.t = d.t+1 > d.h? d.h : d.t-1 < 0+obj.dragArea?0+obj.dragArea:d.t;
						d.l = d.l+1 > d.w? d.w : d.l-1 < 0?0:d.l;
					}
					obj.dragLayer.css({ "top": d.t, "left": d.l});
				}
			})
		}).mouseup(function(){
			obj.isdrag = false;
			if(this.setCapture){ this.releaseCapture(); }
		})
	}
}

var Layer = {
	LayerMode_A: function(){
		var obj = this;
		obj.speed = this.speed || 400;
		obj.queue = this.queue || true;
		obj.bodyT = htm.Top(this.Top || 0);
		obj.bgLayer = this.bgLayer || true;	
		obj.bgLayerEvent = this.bgLayerEvent || false;
		//Layer bg block
		obj.bgLayerTag = $('<div/>');
		obj.bgLayerTag.css({
				"opacity": 0.2
				,"position":"absolute"
				,"top": 0
				,"left": 0
				,"width": document.body.scrollWidth
				,"height": document.body.scrollHeight
				,"background-color":"#000"
				,"z-index": (parseInt(obj.bgLayerTag.prev().css("z-index")) || 1)+1
				,"overflow":"hidden"
			});
		//Layer Content
		obj.content = $('<div/>');
		obj.content.css({
				"position": "absolute"
				,"top": (htm.Height()/2)+obj.bodyT
				,"left": (htm.Width()/2)
				,"border":"#DDD 5px solid"
				,"background-color":"#FFF"
				,"overflow": "hidden"
				,"z-index": (parseInt(obj.content.prev().css("z-index")) || 1)+1
			});
		//Layer Button Close
		obj.butClose = $('<div/>')
			.html('×').attr('title',"关闭").css({
				"position":"absolute"
				,"cursor":"pointer"
				,"top":3
				,"right":3
				,"line-height":"1em"
				,"padding-top":1
				,"padding-left":1
				,"font-weight":700
				,"font-family":"Simsun"
				,"border":"#DDD 1px solid"
				,"background-color":"#EEE"
			}).click(function(){
				obj.close()
			});
		
		//Layer Open
		obj.open = function(){
			obj.bgLayerTag.appendTo(document.body);
			obj.content.appendTo(document.body);
			obj.content.append(obj.butClose);
			var objContent = {};
			if(!obj.bgLayer){ obj.bgLayerTag.remove() }
			if(obj.bgLayerEvent){
				obj.bgLayerTag.click(function(){
					$(this).next().remove();
					$(this).animate({"opacity": 0},obj.speed,function(){ 
						$(this).remove(); 
					})
				})
			}
			objContent.w = obj.content[0].scrollWidth < 250? 250 : obj.content[0].scrollWidth;
			objContent.h = obj.content[0].scrollHeight < 200? 200 : obj.content[0].scrollHeight;
			obj.content.width(0).height(0)
			.animate({
					"left": (htm.Width()/2)-(objContent.w/2)
					,"width": objContent.w
				},{queue:obj.queue,duration:obj.speed})
			.animate({
					"top": ((htm.Height()/2)+obj.bodyT)-(objContent.h/2)	
					,"height": objContent.h
				},obj.spped)
		}
		//drag
		obj.drag = function(){	
			obj.range = this.range || false;
			obj.dragLayer = obj.dragLayer || obj.content;
			obj.dragTag = this.dragTag || obj.dragLayer ;
			if(obj.txtTitle){ obj.dragTag = obj.caption }
			drag.item.call(obj);
		}
		//close
		obj.close = function(){
			obj.content.html('')
			.animate({
				"top": (htm.Height()/2)+obj.bodyT 
				,"height":0
				,"opacity": 0.5
				},{queue:this.queue,duration:this.speed})
			.animate({
				"left": htm.Width()/2
				,"width":0
			},this.speed,function(){
				$(this).remove();
				if(obj.bgLayer){
					obj.bgLayerTag.animate({"opacity": 0},this.speed,function(){ 
						$(this).remove(); 
					})
				}
			})
		}
	},
	LayerMode_B: function(){
		var setload = new Layer.LayerMode_A();
		setload.caption = $('<div/>').css({
			"height": 21
			,"line-height":"1em"
			,"padding":"5px 0px 0px 5px"
			,"background-color":"#F90"
		})
		setload.span = $('<span/>').css({
			"display":"block"
			,"float":"left"
			,"color":"#333"
			,"padding":"6px 15px 3px 15px"
			,"background-color":"#FFF"
		})
		setload.thead = function(str){
			var titContent = setload.txtTitle? setload.caption.append(setload.span.text(setload.txtTitle)) : str;
			this.content.html(titContent);
		}
		setload.tbody = function(str){
			this.content.append(str);
		}
		setload.tfoot = function(str){
			this.content.append(str);
		}
		return setload;
	},
	//Image
	Image: function(){
		//var settings = jquery.extend({},
		//	{callId:'a', ImgW: 500, ImgH: 500, PageEvent: true, top: 50}
		//	options);
		var obj = this;
		obj.id = this.id || null;
		obj.callId = this.callId || null;
		obj.ImgW = this.ImgW || 0;
		obj.ImgH = this.ImgH || 0;
		obj.ImageW = this.ImageW || 0;
		obj.ImageH = this.ImageH || 0;
		obj.top = this.top || 0;
		obj.PageEvent = this.PageEvent || false;
		obj.Speed = this.Speed || 'slow';
		obj.closebutton = this.closebutton || "top";
		obj.pic = $(obj.callId).find("img");
		obj.url = this.url || "rel";
		$(obj.id).css({"cursor":"pointer"}).attr("title","预览大图").click(function(e){  
			new function(){
				obj.htmlH = $("html").height();
				obj.bodyH = document.body.offsetHeight;
				obj.bodyW = document.body.clientWidth;
				obj.bodyT = document.body.scrollTop || document.documentElement.scrollTop;
				window.onresize = function(){
					obj.htmlH = $("html").height();
					obj.bodyH = document.body.offsetHeight;
					obj.bodyW = document.body.clientWidth;
					obj.bodyT = document.body.scrollTop || document.documentElement.scrollTop;
					if(!obj.locking) return false;
					var ImgH = obj.Img.outerHeight()-5;
					var ItemT = obj.Item.position().top;
					obj.locking.css({
						"height": ImgH>obj.bodyH? (ImgH+obj.top+10): obj.bodyH +"px"
					}).next().animate({
						"left": parseInt(obj.bodyW/2)-parseInt(obj.Img.width()/2) +"px"
					},obj.Speed);
				}
			}             
			obj.Item = $('<div/>').addClass("layer-item").prependTo(document.body)
			.css({
				"top": e.pageY,
				"left": e.pageX
			});
			
			obj.locking = $('<div/>').addClass("layer-locking").prependTo(document.body);
			
			obj.Img = $('<img style="padding-'+ obj.closebutton +':18px;"/>').appendTo(obj.Item).attr("src",$(this).attr($(this).attr(obj.url)?obj.url : "src")).val(0).css({
				"margin":"auto",
				"width": obj.ImageW ? obj.ImageW :"auto",
				"height": obj.ImageH ? obj.ImageH :"auto",
				"display":"block",
				"background-color":"#FFF"
			}).hide();
			if(obj.ImgW && !obj.ImageW){if(obj.Img.width() > obj.ImgW){ obj.Img.width(obj.ImgW); }}
			if(obj.ImgH && !obj.ImageH){if(obj.Img.height() > obj.ImgH){ obj.Img.height(obj.ImgH); }}
			
			var Top = obj.top? obj.top+obj.bodyT : parseInt(obj.htmlH/2)-parseInt(obj.Img.outerHeight()/2)+obj.bodyT;
			obj.Item.animate({
				"width": obj.Img.outerWidth(),
				"top": Top +"px",
				"left": parseInt(obj.bodyW/2)-parseInt(obj.Img.outerWidth()/2) +"px",
				"height": obj.Img.outerHeight()
			},"slow",function(){ 
				obj.Img.show(); 
			});
			obj.locking.css({
				"height": obj.Img.outerHeight()>obj.bodyH? (obj.Img.outerHeight()+obj.top+10): obj.bodyH +"px"
			}).animate({"opacity":0.2},obj.Speed);
			
			obj.close = $('<div style="'+ obj.closebutton +':-5px;"/>').css({
				"position":"absolute",
				"left":0,
				"right":0,
				"border-left": "#DDD 5px solid",
				"border-right": "#DDD 5px solid",
				"height": 23,
				"background-color":"#DDD",
				"z-index":1005
			}).prependTo(obj.Item);
			obj.button = $("<div/>").addClass("layer-closebutton").attr("title","关闭").prependTo(obj.close).hover(function(){
				this.style.backgroundPosition = "right center"
			},function(){
				this.style.backgroundPosition = "left center"
			})
			
			obj.locking[0].onclick = obj.button[0].onclick = function(){
				window.onresize = null;
				obj.Item.fadeOut(obj.Speed,function(){
					$(this).remove();
					obj.locking.fadeOut(obj.Speed,function(){$(this).remove()});
				});
			};
			//
			if(obj.PageEvent){
				obj.Img.click(function(e){
					var num = e.pageX < (obj.bodyW/2)? parseInt(obj.Img.val())-1 : parseInt(obj.Img.val())+1;
					if(num < 0 || num >= obj.pic.length){ return false; }
					obj.Img.attr("src",obj.pic.eq(num).attr($(this).attr(obj.url)?obj.url : "src")).val(num)
					.css({
						"width": obj.ImageW ? obj.ImageW : "auto",
						"height": obj.ImageH ? obj.ImageH :"auto"
					}).hide();
					if(obj.ImgW && !obj.ImageW){if(obj.Img.width() > obj.ImgW){ obj.Img.width(obj.ImgW); }}
					if(obj.ImgH && !obj.ImageH){if(obj.Img.height() > obj.ImgH){ obj.Img.height(obj.ImgH); }}
					
					obj.Item.animate({
						"width": obj.Img.outerWidth(),
						"height": obj.Img.outerHeight(),
						"left": (parseInt(obj.bodyW/2)-parseInt(obj.Img.width()/2)) +"px"
					},obj.Speed,function(){
						obj.Img.show();		
					});
					obj.locking.css({
						"height": obj.Img.outerHeight()>obj.bodyH? (obj.Img.outerHeight()+obj.top+10): obj.bodyH +"px"
					});
				}).mousemove(function(e){
					var num = parseInt(this.value);
					this.className = e.pageX < (obj.bodyW/2)? "layer-precur" : "layer-nextcur";
					$(this).attr("title",e.pageX < (obj.bodyW/2)?"上一张:"+ BNext(num-1) : "下一张:"+ BNext(num+1));
				});
				function BNext(n){
					return (n < 0 || n >= obj.pic.length)? "没有了" : obj.pic.eq(n).attr("alt");
				}
			}
		})
	}
	/* 
	#图层相册 End
	*/
}

if(jQuery.validator !=undefined){
    $(function(){
        jQuery.validator.setDefaults({
            errorElement: "var"
        });
    })
}
function LayerMode(){
	var newLayer = new Layer.LayerMode_B();
	return newLayer;
}
var htm = new function(){
	return {
		Top: function(val){
			return parseInt(val) || (document.body.scrollTop || document.documentElement.scrollTop);
		},
		Width: function(val){
			return parseInt(val) || document.body.clientWidth;
		},
		Height: function(val){
			return parseInt(val) || $("html").height();
		}
	}
}
//$(function(){
//	$("form#article_comment ul:first span a").attr("href","javascript:void(0)").click(function(){
//		var d = new LayerMode();
//		//d.queue = true;	//弹出效果
//		//d.speed = "fast";	//弹出耗时 默认 400ms
//		//d.bgLayer = false;	//false 关闭背景层 默认 true
//		//d.bgLayerTag;	//背景层标签
//		//d.bgLayerEvent = true;	//默认背景层快速关闭事件 true 开启 默认 false
//		//d.butClose = null;	//关闭按钮 null or 空白 删除
//		d.txtTitle = "11111";	//选择默认头部标题模式 输入显示标题 (限文本)
//		d.thead("22222");	//头部部位(自定义html) d.txtTitle 配置后 输入内容无效
//		d.tbody($('<div/>').load('http://127.0.0.1/Home/new/login.htm'));	//主题部位(自定义html)
//		//d.tfoot("底部块");	//底部部位(自定义html)
//		d.open();
//		//d.dragTag = d.content;	//拖动控制标签 不存在更换 d.content 内容标签 (d.txtTitle配置 该项无效)
//		d.range = true;	//拖动范围 true 禁当前窗口,默认 false
//		d.drag();		//启用拖动
//		//cid[a.index(this)] = d;
//	});
//})




